package com.lancoo.edu.platform.operation.commons.controller;

import com.lancoo.edu.platform.operation.commons.controller.base.BaseResultController;
import com.lancoo.edu.platform.operation.commons.dto.BaseResult;
import com.lancoo.edu.platform.operation.commons.service.bo.SystemInfoBoService;
import com.lancoo.edu.platform.operation.commons.annotation.CheckToken;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统信息控制器
 *
 * @author pky
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/common/system")
public class SystemInfoController extends BaseResultController {

    private final SystemInfoBoService systemInfoBoService;

    /**
     * 获取系统信息
     *
     * @return 系统信息
     */
    @GetMapping(value = "info")
    public BaseResult getSystemInfo() {
        return success(systemInfoBoService.getSystemInfo());
    }

    /**
     * 获取子系统列表
     *
     * @param sysIds 指定子系统ID串，用英文逗号隔开
     * @return 子系统列表
     */
    @GetMapping(value = "list")
    public BaseResult getBySysIds(String sysIds) {
        if (StringUtils.isBlank(sysIds)) {
            return error("系统ID串不可为空");
        }
        return success(systemInfoBoService.getSystemList(sysIds));
    }


    /**
     * 获取子系统状态
     *
     * @param sysIds 制度子系统ID串，用英文逗号隔开
     * @return 子系统状态列表
     */
    @CheckToken
    @GetMapping("/state")
    public BaseResult getSystemState(String sysIds) {
        if (StringUtils.isBlank(sysIds)) {
            return error("系统ID串不可为空");
        }
        return success(systemInfoBoService.getSystemState(sysIds));
    }
}
